﻿using System;
using System.Collections.Generic;
using System.Text;
using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.MaillingPack
{
    [Serializable()]
    public class MaillingChildInfo : Csla.ReadOnlyBase<MaillingChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _email = string.Empty;

        private DateTime _dataCadastro = DateTime.Now;

        private string _status = string.Empty;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Email
        {
            get
            {
                return _email;
            }
        }

        public DateTime DataCadastro
        {
            get
            {
                return _dataCadastro;
            }
        }

        public string DataCadastroShortString
        {
            get
            {
                return _dataCadastro.ToString("dd/MM/yyyy");
            }
        }

        public string DataCadastroFullString
        {
            get
            {
                return _dataCadastro.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public string Status
        {
            get
            {
                return _status;
            }
        }

        public string StatusString
        {
            get
            {
                switch (_status)
                {
                    case "S":
                        return "Recebe E-mail";
                    case "N":
                        return "Não Recebe E-mail";
                    case "I":
                        return "E-mail Inválido";
                    default:
                        return "";
                }

            }
        }

        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in MaillingChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static MaillingChildInfo GetMaillingChildInfo(SafeDataReader dr)
        {
            return new MaillingChildInfo(dr);
        }

        private MaillingChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _email = dr.GetString("Email");
            _dataCadastro = dr.GetDateTime("DataCadastro");
            _status = dr.GetString("Status");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
